home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
gnu
/
dejagnu.lha
/
dejagnu-1.0.1
/
tcl
/
tests
/
while.test
< prev
Wrap
Text File
|
1992-11-06
|
3KB
|
93 lines
# Commands covered: while
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright 1991 Regents of the University of California
# Permission to use, copy, modify, and distribute this
# software and its documentation for any purpose and without
# fee is hereby granted, provided that this copyright notice
# appears in all copies. The University of California makes no
# representations about the suitability of this software for any
# purpose. It is provided "as is" without express or implied
# warranty.
#
# $Header: /sprite/src/lib/tcl/tests/RCS/while.test,v 1.5 91/09/08 13:43:30 ouster Exp $ (Berkeley)
if {[string compare test [info procs test]] == 1} then {source defs}
test while-1.1 {basic while loops} {
set count 0
while {$count < 10} {set count [expr $count+1]}
set count
} 10
test while-1.2 {basic while loops} {
set value xxx
while {2 > 3} {set value yyy}
set value
} xxx
test while-2.1 {continue in while loop} {
set list {1 2 3 4 5}
set index 0
set result {}
while {$index < 5} {
if {$index == 2} {set index [expr $index+1]; continue}
set result [concat $result [lindex $list $index]]
set index [expr $index+1]
}
set result
} {1 2 4 5}
test while-3.1 {break in while loop} {
set list {1 2 3 4 5}
set index 0
set result {}
while {$index < 5} {
if {$index == 3} break
set result [concat $result [lindex $list $index]]
set index [expr $index+1]
}
set result
} {1 2 3}
test while-4.1 {errors in while loops} {
set err [catch {while} msg]
list $err $msg
} {1 {wrong # args: should be "while test command"}}
test while-4.2 {errors in while loops} {
set err [catch {while 1} msg]
list $err $msg
} {1 {wrong # args: should be "while test command"}}
test while-4.3 {errors in while loops} {
set err [catch {while 1 2 3} msg]
list $err $msg
} {1 {wrong # args: should be "while test command"}}
test while-4.4 {errors in while loops} {
set err [catch {while {"a"+"b"} {error "loop aborted"}} msg]
list $err $msg
} {1 {can't use non-numeric string as operand of "+"}}
test while-4.5 {errors in while loops} {
set x 1
set err [catch {while {$x} {set x foo}} msg]
list $err $msg
} {1 {expression didn't have numeric value}}
test while-4.6 {errors in while loops} {
set err [catch {while {1} {error "loop aborted"}} msg]
list $err $msg $errorInfo
} {1 {loop aborted} {loop aborted
while executing
"error "loop aborted""
("while" body line 1)
invoked from within
"while {1} {error "loop aborted"}"}}
test while-5.1 {while return result} {
while {0} {set a 400}
} {}
test while-5.2 {while return result} {
set x 1
while {$x} {set x 0}
} {}